<template>
	<van-swipe-cell @click="handleSwipeClick">
		<template v-if="leftActions?.details?.length > 0" #left>
			<van-button
				v-for="_item in leftActions.details"
				:key="_item.uIActionTag"
				square
				type="primary"
				:text="_item.caption"
				@click.stop="handleActionClick(_item, $event)"
			/>
		</template>
		<slot v-if="hasSlot('default')" @click="handleClick" name="default"></slot>
		<van-cell v-else @click="handleClick" :title="item.srfmajortext"></van-cell>
		<template v-if="rightActions?.details?.length > 0" #right>
			<van-button
				v-for="_item in rightActions.details"
				:key="_item.uIActionTag"
				square
				type="primary"
				:text="_item.caption"
				@click.stop="handleActionClick(_item, $event)"
			/>
		</template>
	</van-swipe-cell>
</template>
<script setup lang="ts">
import { MDCtrlItemProps } from '../md-ctrl';

const emit = defineEmits<{
	(name: 'item-action-click', logic: any, $event: any): void;
	(name: 'item-click', $event: any): void;
}>();
const props = defineProps(MDCtrlItemProps);
const handleActionClick = (logic: any, $event: any) => {
	emit('item-action-click', logic, $event);
};

const handleSwipeClick = (tag: string) => {
	if ('outside' == tag) {
		return;
	}
	emit('item-click', null);
};
const handleClick = ($event: any) => {
	emit('item-click', $event);
};
const hasSlot = (name: string): boolean => {
	return !!useSlots()[name];
};
</script>
